#include "pika_bsp.h"
#include "pika_config.h"
#include "main.h"
#include <stdio.h>
/* support interrupt */

void __platform_disable_irq_handle(){
    __disable_irq();
}
void __platform_enable_irq_handle(){
    __enable_irq();
}



/* support delay_us */

void delay_us(uint32_t udelay) {
    uint32_t startval, tickn, delays, wait;

    startval = SysTick->VAL;
    tickn = HAL_GetTick();
    delays = udelay * 64;  // delay 1us when delays = 64
    if (delays > startval) {
        while (HAL_GetTick() == tickn) {
        }
        wait = 64000 + startval - delays;
        while (wait < SysTick->VAL) {
        }
    } else {
        wait = startval - delays;
        while (wait < SysTick->VAL && HAL_GetTick() == tickn) {
        }
    }
}

/* support download python script by uart1 */
uint8_t pika_memory_lock = 0;
uint8_t __is_locked_pikaMemory(void){
    return pika_memory_lock;
}


